import defaultSettings from '@/settings'
import Cookies from 'js-cookie';
const {
    showSettings,
    tagsView,
    fixedHeader,
    sidebarLogo
} = defaultSettings

/* 单独处理颜色主题 theme */
let themeObjStr = {
    key: 'theme',
    value: '#409EFF'
};
if (Cookies.get('MY_SET')) {
    themeObjStr = JSON.parse(Cookies.get('MY_SET'));
} else {
    themeObjStr = {
        key: 'theme',
        value: '#409EFF'
    }
}

const state = {
    theme: themeObjStr.value,
    showSettings: showSettings,
    tagsView: tagsView,
    fixedHeader: fixedHeader,
    sidebarLogo: sidebarLogo
}
const mutations = {
    CHANGE_SETTING: (state, {
        key,
        value
    }) => {
        if (state.hasOwnProperty(key)) {
            state[key] = value
        }
    },
}

const actions = {
    changeSetting({
        commit
    }, data) {
        commit('CHANGE_SETTING', data)
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
